/**
 * 
 */
package ar.edu.unq.svnpermission.ui.model;

import java.util.List;

import org.apache.wicket.model.IModel;

import ar.edu.unq.svnpermission.domain.Folder;
import ar.edu.unq.svnpermission.domain.Permission;
import ar.unq.edu.svnpermission.homes.FolderHome;

/**
 * Representa el caso de uso para las Carpetas.
 * @author nicolas
 */
public class Folders extends UseCase {
	private static final long serialVersionUID = 1L;
	private Folder rootFolder;
	private Folder selectedFolder;
	
	public Folders()
	{
		this.setRootFolder(this.getHome(Folder.class, FolderHome.class).getRootFolder());
	}
	
	public Folders(Folder rootFolder)
	{
		this.setRootFolder(rootFolder);
	}

	public Folders getObject() {
		return this;
	}
	
	public String getFolderName() {
		return this.getSelectedFolder() != null ? this.getSelectedFolder().getName() : "";
	}
	
	public List<Permission> getPermissionsList()
	{
		return new Permissions(this.getSelectedFolder()).getAll();
	}

	//GETTERS AND SETTERS
	public Folder getRootFolder() {
		return rootFolder;
	}

	public void setRootFolder(Folder rootFolder) {
		this.rootFolder = rootFolder;
	}
	
	public Folder getSelectedFolder() {
		return selectedFolder;
	}

	public void setSelectedFolder(Folder selectedFolder) {
		this.selectedFolder = selectedFolder;
	}	
	
	public void detach() {
		// TODO Auto-generated method stub
	}

	public void setObject(Folders object) {
		this.setRootFolder(object.getRootFolder());
		this.setSelectedFolder(object.getSelectedFolder());
		
	}	
	
	public void remove()
	{
		
		this.getRootFolder().removeChildFolder(this.getSelectedFolder());
		this.getHome(Folder.class, FolderHome.class).update(this.getRootFolder());
	}
	
}
